package com.richard.main.ui.manager

import androidx.fragment.app.FragmentManager
import androidx.viewpager.widget.ViewPager
import com.ashokvarma.bottomnavigation.BottomNavigationBar
import com.ashokvarma.bottomnavigation.BottomNavigationItem
import com.richard.main.R
import com.richard.main.ui.adapter.MainPagerAdapter

/**
 ***************************************
 * 项目名称:Giggle
 * @Author wuzhiguo
 * 邮箱：wuzhiguo@ksjgs.com
 * 创建时间: 2020/7/26     3:39 PM
 * 用途:
 ***************************************
 */
object MainTabManager {
    fun setMainTab(bottomBar : BottomNavigationBar, viewPager: ViewPager, fm : FragmentManager) {
        bottomBar
            .addItem(
                BottomNavigationItem(R.drawable.icon_b_home_true, R.string.main_tab_home)
                    .setInactiveIconResource(R.drawable.icon_b_home_false)
            )
            .addItem(
                BottomNavigationItem(R.drawable.icon_b_person_true, R.string.main_tab_person)
                    .setInactiveIconResource(R.drawable.icon_b_person_false)
            )
            .setFirstSelectedPosition(0)
            .initialise()

        bottomBar.setTabSelectedListener(object : BottomNavigationBar.OnTabSelectedListener {
            override fun onTabReselected(position: Int) {}

            override fun onTabUnselected(position: Int) {}

            override fun onTabSelected(position: Int) {
                viewPager.currentItem = position
            }
        })

        viewPager.adapter = MainPagerAdapter(fm)
        viewPager.currentItem = 0
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrollStateChanged(state: Int) {}

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {}

            override fun onPageSelected(position: Int) {
                bottomBar.selectTab(position)
            }
        })
    }


}
